package com.js.data.common.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateUtil {

    public static final DateTimeFormatter DATE_NO_HORIZONTAL_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");


    public static final DateTimeFormatter DATE_TIME_NO_HORIZONTAL_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static String getDate() {
        return LocalDateTime.now().format(DATE_FORMATTER);
    }
    public static String getDateTime() {
        return LocalDateTime.now().format(DATE_TIME_NO_HORIZONTAL_FORMATTER);
    }
    public static LocalDateTime timestampToDatetime(long timestamp) {
        Instant instant = Instant.ofEpochMilli(timestamp);
        return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
    }

    public static String timestampToStr(long timestamp) {
        return timestampToDatetime(timestamp).format(DATE_TIME_FORMATTER);
    }


    public static String localDateTimeToStr(LocalDateTime localDateTime) {
        return localDateTime.format(DATE_TIME_FORMATTER);
    }
}

